package com.vrv.vap.baseline.service.impl;

import com.vrv.vap.baseline.config.ExcelTemplateConfig;
import com.vrv.vap.baseline.entity.ActGeProperty;
import com.vrv.vap.baseline.mapper.ActGePropertyMapper;
import com.vrv.vap.baseline.service.AbstractExcelExportService;
import com.vrv.vap.baseline.util.FileOperationUtil;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.util.List;

@Service
public class ActGePropertyExportService extends AbstractExcelExportService<ActGeProperty> {
    public static final String key = "act_ge_property";
    private final ActGePropertyMapper actGePropertyMapper;

    public ActGePropertyExportService(FileOperationUtil fileOperationUtil, ExcelTemplateConfig excelTemplateConfig, ActGePropertyMapper actGePropertyMapper) {
        super(fileOperationUtil, excelTemplateConfig, key);
        this.actGePropertyMapper = actGePropertyMapper;
    }

    @Override
    protected List<ActGeProperty> getAllData() {
        return actGePropertyMapper.selectAll();
    }

    @Override
    protected void processData(List<ActGeProperty> dataList, String format) throws IOException {
        for (ActGeProperty property : dataList) {
            String value = property.getValue();
            if (value != null && value.length() > maxCellLength) {
                String fileName = property.getName() + ".txt";
                File file = fileOperationUtil.createFile(fileName, key, format);
                fileOperationUtil.writeContentToFile(file, value);
                property.setValue(fileName);
            }
        }
    }

    @Override
    protected Class<ActGeProperty> getEntityClass() {
        return ActGeProperty.class;
    }
}